// app.js
App({
	onLaunch() {
		// 展示本地存储能力
		const logs = wx.getStorageSync('logs') || []
		logs.unshift(Date.now())
		wx.setStorageSync('logs', logs)

		// 登录
		// wx.login({
		// 	success: res => {
				// 发送 res.code 到后台换取 openId, sessionKey, unionId
			// }
		// })
	},
	request(s){
		if(!s.data){
			s.data = {}
		}
		s.data.openId = wx.getStorageSync('openId');
		let header = {};
		header = {
			// 'content-type': 'application/x-www-form-urlencoded',
			'content-type': 'application/json',
			'Cookie': 'JSESSIONID=' + wx.getStorageSync("openId"),
			'Authorization': "Bearer " + wx.getStorageSync("token")
		}

		wx.request({
			url: this.globalData.host + s.url,
			data: s.data || {},
			method: s.method || 'GET',
			header: header,
			timeout: 20000,
			success: (result) => {
				s.success && s.success(result.data);
			},
			fail: (res) => {
				s.fail && s.fail(res);
			},
			complete: (res) => {
				s.complete && s.complete(res);
			},
		})
	},
	globalData: {
		userInfo: null,
		navBarHeight: 0,
		// navBarTop: 0,

		// 项目地址
		downUrl:'https://sport.yunqikeji.top',
		host:'https://sport.yunqikeji.top/prod-api'

		// 测试地址
		// downUrl:'http://192.168.0.20:8010',
		// host: "http://192.168.0.20:8010"
	},
	// getHeadHei(){   // 设置顶部空余高度
	// 	const systemInfo = wx.getSystemInfoSync();  // 获取系统信息
	// 	const menuButtonInfo = wx.getMenuButtonBoundingClientRect();  // 胶囊按钮位置信息
	// 	this.globalData.navBarHeight = (menuButtonInfo.top - systemInfo.statusBarHeight) * 2 + menuButtonInfo.height + systemInfo.statusBarHeight;
	// 	this.globalData.navBarTop = menuButtonInfo.top;
	// }
})
